package com.spring.hotel.controller;

import com.spring.hotel.common.JsonResponse;
import com.spring.hotel.entity.Checkin;
import com.spring.hotel.entity.Drinks;
import com.spring.hotel.entity.PageDTO;
import com.spring.hotel.service.CheckinService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;


@RestController
@RequestMapping("/hotel/checkin")
public class CheckinController {

    @Autowired
    private CheckinService checkinService;

    //列表展示入住房间
    @RequestMapping(value = "/list",method = RequestMethod.GET)
    public JsonResponse list(Integer id, PageDTO pageDTO) {
        return checkinService.pageList(id,pageDTO);
    }

    //添加预约
    @RequestMapping(value = "/insert",method = RequestMethod.POST)
    public JsonResponse insert(@RequestBody Checkin checkin) {
        checkinService.save(checkin);
        return JsonResponse.success(null);
    }

    //预约转入住
    @RequestMapping(value = "/update",method = RequestMethod.PUT)
    public JsonResponse update(@RequestBody Checkin checkin){
        String userid = checkin.getUserid();
        return checkinService.updateByUser(userid);
    }

    //用户状态
    @RequestMapping(value = "/state",method = RequestMethod.GET)
    public JsonResponse getState(Integer userid){
        return checkinService.gerState(userid);
    }

    //逻辑删除
    @RequestMapping(value = "/delete",method = RequestMethod.PUT)
    public JsonResponse delete(@RequestBody Checkin checkin){
        checkinService.delete(checkin);
        return JsonResponse.success(null);
    }

    //列表展示入住列表
    @RequestMapping(value = "/admin/insert",method = RequestMethod.POST)
    public JsonResponse insert1(@RequestBody Checkin checkin) {
        checkinService.save(checkin);
        return JsonResponse.success(null);
    }

    //修改
    @RequestMapping(value = "/admin/update",method = RequestMethod.PUT)
    public JsonResponse updateUser(@RequestBody Checkin checkin) throws Exception {
        checkinService.updateById(checkin);
        return JsonResponse.success(null);
    }

    //删除
    @RequestMapping(value = "/admin/delete/{id}",method = RequestMethod.DELETE)
    public JsonResponse delete(@PathVariable String id) {
        checkinService.removeById(id);
        return JsonResponse.success(null);
    }

    //分页查询
    @RequestMapping(value = "/admin/list",method = RequestMethod.GET)
    public JsonResponse list(Checkin checkin, PageDTO pageDTO) {
        return checkinService.pageList(checkin,pageDTO);
    }
}
